Ext.define('PJ.view.messagemanagement.PreChoisedList', {
    extend: 'AM.default.DefaultList',
    alias: ['widget.messagemanagementPreChoisedList'],
    initComponent: function(){
        this.columns = [{
            header: '登录号',
            dataIndex: 'loginID',
            width:'25%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            header: '姓名',
            dataIndex: 'userName',
            width:'30%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            header: '所属部门',
            dataIndex: 'deptName',
            width:'40%',
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        },{
            dataIndex: 'userId',
			hidden : true,
            renderer: function(value, meta, record){
                meta.tdAttr = 'data-qtip="' + value + '"';
                return value;
            }
        }];
        if(this.isContained.userType=='guanliyuan'){
            this.store = Ext.create('PJ.' + prototype + '.messagemanagement.PreChoisedListAdmin', {
                isLoad: false
            });
        }else if(this.isContained.userType=='xueyuan'){
            this.store = Ext.create('PJ.' + prototype + '.messagemanagement.PreChoisedListUser', {
                isLoad: false
            });
        }else{
        	this.store = Ext.create('PJ.' + prototype + '.messagemanagement.PreChoisedListUser', {
                isLoad: false
            });
        	// 4.0强制更改store参数写法
            var params = this.store.proxy.extraParams;
            var newParams = {
        		ifSearchAdmin:1
            };
            Ext.apply(params, newParams);
        }

//      var selectScopeId=$(document.getElementById("selectScope")).find("option:selected")[0].value;
        this.loadType = gj_onlineLearning_constant.loadType;
        this.callParent(arguments);
    },
    onAddClick: function(button){
        var me = this;
        var records = me.getSelectionModel().getSelection();
        var messagemanagementChoisedList = me.up("container").down("messagemanagementChoisedList");
        var model;
        var m = new Map();
        for (i in records) {
        	if(isNaN(i)){
        		continue;
        	}
			model = Ext.create("PJ.model.messagemanagement.PreChoisedList");
            model.set({
                //列表上的所有字段属性，赋值空
                "userName": records[i].data.userName,
				"userId":records[i].data.userId,
				"loginID":records[i].data.loginID,
                "deptName":records[i].data.deptName
            });
	        me.getStore().remove(records[i]);
	        //model.commit();//提交model，如果添加此句则列表上不会再显示左上角修改后的标识符
	        m.set(records[i].data.userId,model);
        }
        var store = messagemanagementChoisedList.getStore();
		if(store.data.items.length!=0){
			var dataa=store.data.items;
			for(o in dataa){
				if(isNaN(o)){
					continue;
				}
				if(m.get(dataa[o].data.userId)){
					m.delete(dataa[o].data.userId);
				}
			}
		}
		m.forEach(function(record){
			store.add(record);//将刚刚新建的空数组添加到列表中
		})
    },
    listeners: {
        viewready: function(){
            this.addDocked([{
                dock: 'top',
                xtype: "searchform",
                columnCount: 2,
                fieldDefaults: {
    				labelAlign: 'left',
    				labelWidth: 55
    			},
                items: [{
                    xtype: "textfield",
                    name: "searchUserName",
                 // labelAlign: 'left',
                    emptyText: '请输入姓名',
                    fieldLabel: '姓名'
                },{
                    xtype: "textfield",
                    name: "searchLoginID",
                 // labelAlign: 'left',
                    emptyText: '请输入登录号',
                    fieldLabel: '登录号'
                }],
                grid: this
            }, {
                xtype: 'toolbar',
                dock: 'top',
                displayInfo: true,
                items: [this.addButton]
            }]);
            // 触发权限过滤事件
            this.fireEvent("permission", this);
        }
    }
});
